package com.shop.ddp.controller;

import com.shop.ddp.entity.User;
import com.shop.ddp.service.UserService;
import com.shop.ddp.service.impl.UserServiceImpl;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestAttribute;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

/**
 * @date 2020/9/16 19:20
 */
@Controller
public class UserController {

    @Autowired
    private UserServiceImpl userService;

    @PostMapping("/login")
    public String  login(String username,String password, HttpServletResponse response, HttpServletRequest request){
        User user = userService.getOne(username, password);
        if (user == null){
            request.setAttribute("message","密码错误");
            return "login";
        }else {
            HttpSession session = request.getSession();
            session.setAttribute("user",user);
            return "index";
        }
    }

}
